package com.base.aop;

import java.lang.reflect.Proxy;
import java.util.HashMap;
import java.util.Map;

public class HashMapProxyTest {
    public static void main(String[] args) throws Exception {
        // HandlerInvoker
        final HashMap<String, Object> hashMap = new HashMap<>();
        Object obj = Proxy.newProxyInstance(
                HashMap.class.getClassLoader(), HashMap.class.getInterfaces(), (proxy, method, param) ->{
                        System.out.println(param);
                        // return 语句，原方法的返回值
                       return method.invoke(hashMap, param);
                });
        // 类型判断时
        if (obj instanceof Map) {
            //  接口代理类，能够代理接口生成的所有方法。
            Map<String, Object> mapProxy = (Map) obj;
            mapProxy.put("key1", "value1");
            System.out.println(mapProxy);
            System.out.println(hashMap);
        }

    }
}